interface TableData {
  title: string;
  [key: string]: any;
}

interface TableHeader {
  name: string;
  field: string;
}

interface FormatTableDataParams {
  XAXIS: string[];
  data: {
    actualProvincialLoad: number[];
    provincialLoadForecast: number[];
    actualNewEnergyPower: number[];
    newEnergyPowerForecast: number[];
    actualTieLineLoad: number[];
    tieLineLoadForecast: number[];
  };
}

/**
 * 格式化表格数据函数
 * @param params 参数
 * @returns {object} 返回表格数据和表头
 */
export const formatTableData = (params: FormatTableDataParams) => {
  const { XAXIS, data } = params;

  // 初始化数据
  const _tableData: TableData[] = [
    { title: '统调负荷实际' },
    { title: '统调负荷预测' },
    { title: '新能源出力实际' },
    { title: '新能源出力预测' },
    { title: '联络线出力实际' },
    { title: '联络线出力预测' },
  ];

  XAXIS.forEach((t, i) => {
    _tableData[0][t] = data.actualProvincialLoad[i] || '-';
    _tableData[1][t] = data.provincialLoadForecast[i] || '-';
    _tableData[2][t] = data.actualNewEnergyPower[i] || '-';
    _tableData[3][t] = data.newEnergyPowerForecast[i] || '-';
    _tableData[4][t] = data.actualTieLineLoad[i] || '-';
    _tableData[5][t] = data.tieLineLoadForecast[i] || '-';
  });

  // 表头
  const _tableHeader: TableHeader[] = XAXIS.map((t) => ({
    name: t,
    field: t,
  }));

  return {
    tableData: _tableData,
    tableHeader: _tableHeader,
  };
};
